package com.word.app.controller;

import java.util.HashMap;
import java.util.Map;

import org.apache.catalina.security.SecurityUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.word.app.config.token.JWTToken;
import com.word.app.controller.response.BaseResponse;
import com.word.app.controller.response.Code;
import com.word.app.pojo.UserInfo;
import com.word.app.service.impl.UserInfoServiceImpl;

@RestController
public class UserController {
    @Autowired
    UserInfoServiceImpl service;

    @PostMapping("login")
    public BaseResponse login(@RequestBody UserInfo req){
        String token = service.login(req.getName(), req.getPassword());
        Map<String, String> map = new HashMap<String,String>();
        map.put("token", token);
        map.put("perm", req.getName().equals("root")?"root":"visitor");
        return new BaseResponse().data(map).addCodeMessage(token!=null?Code.C200:Code.C401);
    }

}
